package com.icss.dao;

import com.icss.entity.Record;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface RecordDao extends JpaRepository<Record, Integer>, JpaSpecificationExecutor<Record> {
    @Query(value = "select user_id from t_user where user_name=?1", nativeQuery = true)
    Integer findByusername(String userName);

    @Query(value = "select * from t_vehicle_illegal_record where record_id=?1", nativeQuery = true)
    Record findByid(Integer id);

    @Modifying
    @Query(value = "update User set balance=balance-?1,ableScore = ableScore-?2,numberOfIllegal = numberOfIllegal+1,untreated = untreated-1,deductScore=deductScore+?2 where userId=?3")
    Integer updateByuserName(Integer balance, Integer ableScore, Integer userId);

    @Modifying
    @Query(value = "update t_vehicle_illegal_record set state = 1 where user_id = ?1", nativeQuery = true)
    Integer updateState(Integer userId);
    @Transactional
    @Modifying
    @Query(value = "update t_user set user_name= ?1,tel=?2 where user_id = ?3", nativeQuery = true)
    Integer updateRecord(String username, Integer tel, Integer id);
}
